
/*  csum.c
    For use with TM40.C
    Stephen D. Anderson --- July 5, 1994
*/

#include "stdio.h"
#include "string.h"

    typedef unsigned char byte;

byte Checksum(byte *s, byte nbytes)

/*  Function Checksum() generates the HART checksum of an array of 
bytes by exclusive ORing.

    ON ENTRY:
    s is pointer to array of bytes, nbytes is the number of bytes.

    ON EXIT:
    Returns the checksum.

    REVISION LOG:

*/

{
    byte i,check;
    byte *p;

    for (i=1, check=0, p=s; i<=nbytes; ++i) check ^= *p++;

    return(check);
}

byte Checkpar(byte *s, byte nbytes)

/*  Function Checkpar() generates the HART parity check of an array of 
bytes by ORing.

    ON ENTRY:
    s is pointer to the array of bytes, nbytes is the number of bytes.  

    ON EXIT:
    returns the error check byte.

    REVISION LOG:

*/

{
    byte i,check;
    byte *p;

    for (i=1, check=0, p=s; i<=nbytes; ++i) check |= *p++;

    return(check);
}

